package com.ruoyi.common.core.utils.aliyun;

import com.aliyun.alimt20181012.models.TranslateECommerceRequest;
import com.aliyun.alimt20181012.models.TranslateECommerceResponse;
import com.aliyun.alimt20181012.models.TranslateECommerceResponseBody;
import com.aliyun.alimt20181012.models.TranslateECommerceResponseBody.TranslateECommerceResponseBodyData;

public class TranslateUtils {

	public static Object translate(String source, String scene) {

		com.aliyun.alimt20181012.Client client = ClientUtils.createClient();

		TranslateECommerceRequest translateECommerceRequest = new TranslateECommerceRequest();
		translateECommerceRequest.setFormatType("text");
		translateECommerceRequest.setTargetLanguage("en");
		translateECommerceRequest.setSourceLanguage("zh");
		translateECommerceRequest.setSourceText(source);
		translateECommerceRequest.setScene(scene);

		TranslateECommerceResponse response = null;
		try {
			response = client.translateECommerce(translateECommerceRequest);
		} catch (Exception e) {
			e.printStackTrace();
		}
		TranslateECommerceResponseBody resp = response.getBody();
		TranslateECommerceResponseBodyData data = resp.getData();
		String translated = data.getTranslated();
		return translated;
	}
}
